package com.zlz.m3u8download.bean.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @Author: zhulinzhong
 * @Date: 2024/11/29
 */
@Getter
@AllArgsConstructor
public enum CacheM3u8State {
    // 源加载失败
    SOURCE_LOAD_FAILED(-1),

    // 初始化
    INITIALIZED(0),

    // 已生成索引
    INDEX_GEN_SUCCESS(1),

    // 缓存中
    CACHING(2),

    // 缓存完成
    CACHED_COMPLETED(3);

    private final Integer value;

    // 根据值获取对应的枚举实例的方法，方便在从数据库等获取值后转换为对应的枚举
    public static CacheM3u8State valueOf(int value) {
        for (CacheM3u8State state : CacheM3u8State.values()) {
            if (state.getValue() == value) {
                return state;
            }
        }
        throw new IllegalArgumentException("Invalid cache state value: " + value);
    }
}
